The indexOf() method
This example tests if a string contains a specified word and returns the position of where the word was found

<script type="text/javascript">
var str="W3Schools is great!"
var pos=str.indexOf("School")
if (pos>=0){
   document.write("School found at position: ")
   document.write(pos + "<br />")}
else {
   document.write("School not found!")}
</script>

<p>This example tests if a string contains a specified word. If the word is found it returns the position of the first character of the word in the original string. Note: The first position in the string is 0!</p>